limsResult.abnormalPage = {

    getAbnormalTaskGrid: function () {
        var _this = this;
        return {
            type: 'grid',
            id: 'abnormal-task-list-grid',
            url: limsResult.orderTaskUrl + '/queries/raw',
            readonly: true,
            columns: limsResult.getAbnormalOrderTaskGridColumns(),
            requestData: {
                status_EQ: 'abnormal',
                flag_EQ: '1',
                //createdByOrgId_EQ: workspace.user.ext$.loginorgid
            },
            page: true,
            onLoadSuccess: function (rows) {
                if (Gikam.isNotEmpty(rows)) {
                    this.activeRowByIndex(0)
                }
            },
            onRowActive: function (index, row) {//批次的行激活
            },
            onCellClick: function (field, row) {
                field === 'sampleCode' && row.id && _this.loadRunOrderTaskPage(row)
            },
            toolbar: [{
                type: 'button',
                text: 'LIMS.T_LIMS_ORDER_TASK.BUTTON.CONTINUE',
                icon: 'submit', color: 'success',
                onClick: function () {
                    let grid = Gikam.getComp('abnormal-task-list-grid');
                    let selections = grid.getSelections();
                    if (Gikam.isEmpty(selections)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_ONE_ITEM');
                        return;
                    }
                    Gikam.confirm('GIKAM.MODAL.SUBMIT', 'GIKAM.TIP.SUBMIT', function () {
                        workspace.window.showMask();
                        Gikam.postText(limsResult.runUrl + '/action/abnormal/pass',
                            Gikam.getJsonWrapper(null, [null, selections])).done(function (result) {
                            grid.refresh();
                        }).always(function () {
                            workspace.window.closeMask();
                        });
                    })
                }
            }, {
                type: 'button',
                text: 'LIMS.T_LIMS_ORDER_TASK.BUTTON.STOP',
                icon: 'reject',
                onClick: function () {
                    let grid = Gikam.getComp('abnormal-task-list-grid');
                    let selections = grid.getSelections();
                    if (Gikam.isEmpty(selections)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_ONE_ITEM');
                        return;
                    }
                    Gikam.createLimsModal({
                        title: 'LIMS.T_LIMS_ORDER_TASK.BUTTON.STOP',
                        height: 220,
                        width: 380,
                        onConfirm: function () {
                            var form = Gikam.getComp('confirm-form');
                            if (form.validate()) {
                                let data = form.getData();
                                workspace.window.showMask();
                                Gikam.postText(limsResult.runUrl + '/action/abnormal/stop',
                                    Gikam.getJsonWrapper(data, [null, selections])).done(function (result) {
                                    grid.refresh();
                                }).always(function () {
                                    Gikam.getLastModal().close();
                                    workspace.window.closeMask();
                                });
                            }
                        },
                        m: {
                            type: 'form',
                            id: 'confirm-form',
                            fields: [{
                                field: 'reason',
                                title: 'T_CORE_EMAIL_TEMPLATE.REMARK',
                                validators: ['notEmpty'],
                                type: 'textarea',
                                height: 100,
                            }],
                            columns: 1,
                        }
                    })
                }
            }]
        }
    },

    loadRunOrderTaskPage: function (row) {
        workspace.window.load(limsResult.baseUrl + '/page/run-order-task-abnormal-detail' + Gikam.param({
            ids : row.id,
            runCode: row.runCode,
            parallelId : row.parallelId
        }))
    },

    create: function () {
        var _this = this;
        Gikam.create('layout', {
            id: 'lims-result-audit-list-layout',
            renderTo: workspace.window.$dom,
            center: {
                items: [this.getAbnormalTaskGrid()]
            }
        });
    },

    init: function () {
        this.create();
    }
};
